<%--
  Created by IntelliJ IDEA.
  User: qupen
  Date: 2016/12/13
  Time: 10:02
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="../../include/head.jsp">
    <jsp:param name="title" value="user_list"/>
</jsp:include>

<jsp:include page="../../include/tenant_header.jsp"/>

<jsp:include page="../../include/tenant_sidebar.jsp"/>
<div class="content-wrapper content-wrapper-bg">
    <section class="content-header">
        <h4 class="page-title" style="display: inline-block">事件订阅修改</h4>
    </section>
    <section class="content">
        <div class="box box-primary table-header-line">
            <div class="box-body" style="padding: 0">
                <div class="form-horizontal">
                    <div class="sie-padding-top">
                        <div class="form-group form-group-change">
                            <label class="col-md-6 col-sm-6 sie-left-name">事件名称:</label>
                            <input id="eventId" class="hidden" value="${event.getEventId()}"/>

                            <div class="col-md-6 col-sm-6"
                                 style="color: #666;font-size: 14px;margin-top: 4px;font-weight: 400;">
                                ${event.getEventName()}
                            </div>
                        </div>
                        <c:forEach var="sub" items="${eventSub}">
                            <div class="form-group form-group-change">
                                <div class="col-md-5 col-sm-5 sie-left-name">
                                    <div class="sie-flex-box"
                                         style="line-height: 16px;display: block;text-align: right;margin-top: 0;">
                                        <div class="sie-flex-item item-access" data-value=${sub.device_id}>
                                            <i class="sie-checkbox checked"></i>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-7 col-sm-7"
                                     style="color: #666;font-size: 14px;margin-top: 4px;font-weight: 400;">
                                        ${sub.device_unique_id}
                                </div>
                            </div>
                        </c:forEach>
                        <div class="form-group form-group-change">
                            <div class="col-md-offset-5" style="margin-top: 79px;">
                                <a id="delete_button" class="solid-button-blue" href="javascript:;"
                                   style="margin-right: 30px">删除</a>
                                <a class="solid-button-orange" href="javascript:history.back(-1);">取消</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <%--</div>--%>
    </section>
</div>
<jsp:include page="../../include/foot.jsp"/>
<script>
    $(document).ready(function () {
        planBoxBind();

        $("#delete_button").click(function () {
            var idArr = [];
            var checkBox = $(".item-checked");
            for (var i = 0; i < checkBox.length; i++) {
                idArr.push($(checkBox[i]).data("value"));
            }
            console.log(idArr);
            $.ajax({
                url:"/partner/{tenant}/api/v1/eventRelation/delete".replace("{tenant}",getKeyByUrl()),
                type:"post",
                data:{
                    idArr:idArr,
                    eventId:$("#eventId").val()
                },
                success: function (data) {
                    if(data.result=="SUCCESS"){
                        swal({
                            title: "<spring:message code="label.delete.success"/>!",
                            text: "",
                            type: "warning",
                            showCancelButton: false,
                            showConfirmButton: true,
                            confirmButtonText: "<spring:message code="label.admin.confirm"/>",
                            cancelButtonText: "",
                            animation: "slide-from-top"
                        }, function () {
                            window.location.reload(true);
                        })
                    }else{
                        swal("删除失败","","error");
                    }
                },
                error:function(e) {
                    console.log(e);
                    swal("删除失败","","error");
                }
            })
        });
    });

    function planBoxBind() {
        $('.item-access').bind('click', function () {
            $(this).hasClass('item-checked') ? $(this).removeClass('item-checked') : $(this).addClass('item-checked');
        });
    }
</script>